import org.apache.activemq.ActiveMQConnectionFactory;
import org.junit.BeforeClass;
import org.junit.Test;

import static java.lang.Thread.sleep;
import static java.util.Objects.requireNonNull;
import static org.junit.Assert.assertEquals;

public class TopicTest {
	static ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616");

	@BeforeClass
	public static void setUp() {
		// 创建连接工厂
		factory.setTrustAllPackages(true); // 设置信任所有包
	}

	@Test
	public void testMessageListener_asm() throws Exception {
		TopicProducer.produce(factory, "asm");
		sleep(1000);
		TopicConsumer.createConsumer(factory, "asm").setMessageListener((message_asm) -> assertEquals("Topic asm Received message: Test Message ASM", requireNonNull(TopicConsumer.setMessageListener(message_asm, "asm")).trim()));
	}

	@Test
	public void testMessageListener_se() throws Exception {
		TopicProducer.produce(factory, "se");
		sleep(1000);
		TopicConsumer.createConsumer(factory, "se").setMessageListener((message_se) -> assertEquals("Topic se Received message: Test Message SE", requireNonNull(TopicConsumer.setMessageListener(message_se, "se")).trim()));
	}
}